# eric7.UI.CompareDialog

Module implementing a dialog to compare two files and show the result side by side.

### Global Attributes

None

### Classes

CompareDialog | Class implementing a dialog to compare two files and show the result side by side.
CompareWindow | Main window class for the standalone dialog.

### Functions

removeMarkers | Internal function to remove all diff markers.
sbsdiff | Compare two sequences of lines; generate the delta for display side by side.

## CompareDialog

Class implementing a dialog to compare two files and show the result side by side.

### Derived from

QWidget, Ui_CompareDialog

### Class Attributes

None

### Class Methods

None

### Methods

CompareDialog | Constructor
__appendText | Private method to append text to the end of the contents pane.
__compare | Private method to compare two lists of text.
__fileChanged | Private slot to enable/disable the Compare button.
__generateFormats | Private method to generate the various text formats.
__moveTextToCurrentDiffPos | Private slot to move the text display to the current diff position.
__scrollBarMoved | Private slot to enable the buttons and set the current diff position depending on scrollbar position.
compare | Public method to compare two lists of text.
on_buttonBox_clicked | Private slot called by a button of the button box clicked.
on_diffButton_clicked | Private slot to handle the Compare button press.
on_downButton_clicked | Private slot to go to the next difference.
on_firstButton_clicked | Private slot to go to the first difference.
on_lastButton_clicked | Private slot to go to the last difference.
on_synchronizeCheckBox_toggled | Private slot to connect or disconnect the scrollbars of the displays.
on_upButton_clicked | Private slot to go to the previous difference.
show | Public slot to show the dialog.

### Static Methods

None

#### CompareDialog (Constructor)

CompareDialog(files=None, parent=None)

Constructor

files (list of tuples of (str, str))
  list of files to compare and their label
parent (QWidget)
  parent widget

#### CompareDialog.__appendText

__appendText(pane, linenumber, line, charFormat, interLine=False)

Private method to append text to the end of the contents pane.

pane (QTextedit)
  text edit widget to append text to
linenumber (str)
  number of line to insert
line (str)
  text to insert
charFormat (QTextCharFormat)
  text format to be used
interLine (bool)
  flag indicating interline changes

#### CompareDialog.__compare

__compare(lines1, lines2)

Private method to compare two lists of text.

lines1 (list of str)
  text to compare against
lines2 (list of str)
  text to compare

#### CompareDialog.__fileChanged

__fileChanged()

Private slot to enable/disable the Compare button.

#### CompareDialog.__generateFormats

__generateFormats()

Private method to generate the various text formats.

#### CompareDialog.__moveTextToCurrentDiffPos

__moveTextToCurrentDiffPos()

Private slot to move the text display to the current diff position.

#### CompareDialog.__scrollBarMoved

__scrollBarMoved(value)

Private slot to enable the buttons and set the current diff position depending on scrollbar position.

value (int)
  scrollbar position

#### CompareDialog.compare

compare(lines1, lines2, name1="", name2="")

Public method to compare two lists of text.

lines1 (str or list of str)
  text to compare against
lines2 (str or list of str))
  text to compare
name1 (str)
  name to be shown for the first text
name2 (str)
  name to be shown for the second text

#### CompareDialog.on_buttonBox_clicked

on_buttonBox_clicked(button)

Private slot called by a button of the button box clicked.

button (QAbstractButton)
  button that was clicked

#### CompareDialog.on_diffButton_clicked

on_diffButton_clicked()

Private slot to handle the Compare button press.

#### CompareDialog.on_downButton_clicked

on_downButton_clicked()

Private slot to go to the next difference.

#### CompareDialog.on_firstButton_clicked

on_firstButton_clicked()

Private slot to go to the first difference.

#### CompareDialog.on_lastButton_clicked

on_lastButton_clicked()

Private slot to go to the last difference.

#### CompareDialog.on_synchronizeCheckBox_toggled

on_synchronizeCheckBox_toggled(sync)

Private slot to connect or disconnect the scrollbars of the displays.

sync (bool)
  flag indicating synchronisation status

#### CompareDialog.on_upButton_clicked

on_upButton_clicked()

Private slot to go to the previous difference.

#### CompareDialog.show

show(filename=None)

Public slot to show the dialog.

filename (str)
  name of a file to use as the first file

Up

## CompareWindow

Main window class for the standalone dialog.

### Derived from

EricMainWindow

### Class Attributes

None

### Class Methods

None

### Methods

CompareWindow | Constructor
eventFilter | Public method to filter events.

### Static Methods

None

#### CompareWindow (Constructor)

CompareWindow(files=None, parent=None)

Constructor

files (list of [(str, str), (str, str)])
  list of files to compare and their label
parent (QWidget)
  reference to the parent widget

#### CompareWindow.eventFilter

eventFilter(_obj, event)

Public method to filter events.

_obj (QObject)
  reference to the object the event is meant for (unused)
event (QEvent)
  reference to the event object

Return:
  flag indicating, whether the event was handled

Return Type:
  bool

Up

## removeMarkers

removeMarkers(line)

Internal function to remove all diff markers.

line (str)
  line to work on

Return:
  line without diff markers

Return Type:
  str

Up

## sbsdiff

sbsdiff(a, b, linenumberwidth=4)

Compare two sequences of lines; generate the delta for display side by side.

a (list of str)
  first sequence of lines
b (list of str)
  second sequence of lines
linenumberwidth (int)
  width (in characters) of the linenumbers

Yield:
  tuples of differences. Each tuple is composed of strings as follows.
  - opcode -- one of e, d, i, r for equal, delete, insert, replace
  - lineno a -- linenumber of sequence a
  - line a -- line of sequence a
  - lineno b -- linenumber of sequence b
  - line b -- line of sequence b

Yield Type:
  tuple of (str, str, str, str, str)

Up